<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liujie <1078261686@qq.com>
// +----------------------------------------------------------------------


   /**
     * 根据经纬度计算方圆某公里的经纬度最大和最小值
     * @param  $latitude    纬度    
     * @param  $longitude    经度
     * @param  $raidus        半径范围(单位：米)
     * @return multitype:number 
     */

     function getAround($latitude,$longitude,$raidus){
        $PI = 3.14159265;
        $degree = (24901*1609)/360.0;
        $dpmLat = 1/$degree;
        $radiusLat = $dpmLat*$raidus;
        $minLat = $latitude - $radiusLat;
        $maxLat = $latitude + $radiusLat;
        $mpdLng = $degree*cos($latitude * ($PI/180));
        $dpmLng = 1 / $mpdLng;
        $radiusLng = $dpmLng*$raidus;
        $minLng = $longitude - $radiusLng;
        $maxLng = $longitude + $radiusLng;
        return array ('minLat'=>$minLat, 'maxLat'=>$maxLat, 'minLng'=>$minLng, 'maxLng'=>$maxLng);
    }

     /**
     * php根据经纬度计算两地距离没有调用百度..api接口
     * @param  $lng1    经度1   
     * @param  $lat1    纬度1
     * @param  $lat2    纬度2     
     * @param  $lng2    经度2 
     * @return 返回(单位：米)
     */
     function getDistance($lng1, $lat1, $lng2, $lat2) {
	    $radLat1 = deg2rad($lat1); //deg2rad()函数将角度转换为弧度
	    $radLat2 = deg2rad($lat2);
	    $radLng1 = deg2rad($lng1);
	    $radLng2 = deg2rad($lng2);
	    $a = $radLat1 - $radLat2;
	    $b = $radLng1 - $radLng2;
	    $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
	    return $s;
	 }